Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IL2CPP compliant build for Unity #2044

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

applejag
Copy link

@applejag applejag commented Apr 12, 2019

Adds IL2CPP specific constant checks in code according to @dngulin's guide at #1440 (comment) via new build net462-unity3d

Manually tested in Unity 2018.3.11f1 in editor, WebGL, Windows (Mono), and Windows (IL2CPP).

Scraped together in a hurry. It compiles, tests passes for all builds including this one, deploys fine. Have tried following codebase structure as best I can. Please be brute' on things to fix for this PR and I will get on it.

This PR aims to resolve #1440


Edit: Newtonsoft.Json-for-Unity is now available as an UPM package

To make it more customizable for Unity and easier to use, I've provided a package delivered by Unity Package Manager containing the changes of this pull request. This new repo will be maintained and remain up-to-date, while this pull request will not be.

https://github.com/jilleJr/Newtonsoft.Json-for-Unity

See #2044 (comment)

@dschofield93
Copy link

Hey @jilleJr , great work on this feature - it's much needed for the project we're currently working on! Hey @JamesNK is there any update on whether this feature is planned to be merged into master? We're getting close to needing it for mobile deployment and it would be great to get the update through Nuget as opposed to managing a feature branch. Thanks!

@applejag
Copy link
Author

applejag commented May 9, 2019

Yea well getting it in the actual releases would be grand. Maybe James isn't that active reading pull requests?

For those waiting but could do with building it manually, you can just clone my branch https://github.com/jilleJr/Newtonsoft.Json#feature/unity-il2cpp-compiant (same as from this PR) and start building the code locally by just executing the Build/localbuild.ps1 powershell script.

git clone https://github.com/jilleJr/Newtonsoft.Json --depth 1 --single-branch --branch feature/unity-il2cpp-compiant

# executed inside folder
Build/localbuild.ps1

Followed by just navigating to the folder <repo>\Src\Newtonsoft.Json\bin\Release\net462-unity3d and claim your dll's.

@Admiral18
Copy link

+1
We would need unity webGL support as well

@applejag
Copy link
Author

applejag commented May 30, 2019

@Admiral18
+1
We would need unity webGL support as well

This should in theory work for all IL2CPP configured builds, including standalone (Windows/OS X/Linux), WebGL, iOS, Android, UWP, etc. This new build configuration is good for all AOT compilations as well as some extra requirements needed for IL2CPP compilation.

So far tested and confirmed working on standalone & WebGL builds

@dbastien
Copy link

Can has please!

@thsbrown
Copy link

Would be great to have this pulled into master

@applejag
Copy link
Author

applejag commented Jul 18, 2019

Newtonsoft.Json for Unity is now available as an Unity Package!

https://github.com/jilleJr/Newtonsoft.Json-for-Unity

For convenience I've prepared a Unity Package you all can abuse your socks off.

Installation via Unity Package Manager (UPM)

Requires Unity Editor 2018.1 or above, as UPM was first shipped with 2018.1.

Open <project>/Packages/manifest.json, add the scope in scopedRegistries and the dependency jillejr.newtonsoft.json-for-unity like so:

{
  "scopedRegistries": [
    {
      "name": "Packages from jillejr",
      "url": "https://npm.cloudsmith.io/jillejr/newtonsoft-json-for-unity/",
      "scopes": ["jillejr"]
    }
  ],
  "dependencies": {
    "jillejr.newtonsoft.json-for-unity": "12.0.101",

    "com.unity.modules.ai": "1.0.0",
    "com.unity.modules.animation": "1.0.0",
    "com.unity.modules.assetbundle": "1.0.0",
    "com.unity.modules.audio": "1.0.0",
    "com.unity.modules.cloth": "1.0.0",
    "com.unity.modules.director": "1.0.0",
    "com.unity.modules.imageconversion": "1.0.0",
    "// cropping rest of packages for readability"
  }
}

This project will live long for a while, so it's all safe to use. Now also featuring help from Dustin Horne (aka ParentElement himself)

Note - far from alone

There are plenty of projects that gives JSON parsing in Unity. However most of them seems to be discontinued:

While my repo will live for some time, for future reference here are some good alternatives (that all work in Unity) that I personally recommend if my solution dips below your expectations:

Happy Json parsing!

@maskedmouse
Copy link

maskedmouse commented Jul 24, 2019

@jilleJr I've added the package to my new Unity project (2018.4.4 but also 2019.1.11) but building fails.
Plugins are colliding for Windows x64 IL2CPP and manually fixing that, then build again it pretends the newtonsoft json namespace doesn't exist.

@applejag
Copy link
Author

@jilleJr I've added the package to my new Unity project (2018.4.4 but also 2019.1.11) but building fails.
Plugins are colliding for Windows x64 IL2CPP and manually fixing that, then build again it pretends the newtonsoft json namespace doesn't exist.

Super weird I did not find this before! Easily reproduced, even via local installation instead of UPM. It's like "worked on my machine a week ago". Don't know what could be different now.
I've added an issue in my repo with more details and I will tackle it as soon as I can. I'm interested in the what's and how's. Maybe Josh can help. Follow the issue over here: applejag#3

@ghost
Copy link

ghost commented Sep 18, 2019

+1 It must have feature, Unity used wide novadays and has direct support will'b great

@damdo
Copy link

damdo commented Nov 7, 2019

Hey @JamesNK any hope to get this in the next release? It would be great to have Unity supported! Thank you

@Dryra
Copy link

Dryra commented Dec 18, 2019

Hello @jilleJr,
Thank you for your fork, saved me a lot of time!
Just as info for someone trying this out and having problems with the script build.ps1, you have to change the path to MSBUILD.exe in GetMsBuildPath(), the path in the new Visual Studio 2019 is not "MSBuild\15.0\Bin\MSBuild.exe" rather MSBuild\Current\Bin\MSBuild.exe

So just change this line:
return join-path $path 'MSBuild\15.0\Bin\MSBuild.exe'
with
return join-path $path 'MSBuild\Current\Bin\MSBuild.exe'

@damdo
Copy link

damdo commented Jan 30, 2020

Hey @JamesNK any hope to get this upstream? Having it support Unity would be really amazing for all of us! Thank you

@AlexFolland
Copy link

I installed the above-linked UPM package from @jilleJr and switched my Unity 2019.3.4f1 project's Windows build scripting backend from Mono to IL2CPP. My project was able to be built with Mono but not IL2CPP. I got some obscure compiler error message about JsonConvert.DeserializeObject having an extra character that it didn't expect, but my JSON was completely valid. From my research, I found and used the workaround in the following linked comment. I just placed the code in the following linked comment directly before my JsonConvert.DeserializeObject call and it worked.

Azure/azure-iot-sdk-csharp#213 (comment)

I'm not sure why. Maybe I am using an old version of the build chain or something. Anyway, maybe this will help someone who had the same issue later. Thanks to @jilleJr for this pull request and the Unity-compatible fork. I hope @JamesNK can merge this pull request soon, as I don't see a downside. Also thanks for the JSON tool.

@applejag
Copy link
Author

applejag commented Jul 4, 2020

Hi @AlexFolland. This issue has had a lot of progress in the background by now. Here's the news:

  • My fork is available via UPM and OpenUPM which makes it possible to use the DLLs without having to embed them into your repository and take up space there. I've not had good contact with James but my guess is that he doesn't have overly much time on adding that as a distribution point when there's alternatives available already.

  • My fork has now a sister repo, the jilleJr/Newtonsoft.Json-for-Unity.Converters where I've received help from both Dustin Horne (aka. ParentElement, author of the original JSON .NET For Unity package from the Assets Store) and Wanzyee Wang (aka. Wanzyee Studios, author of the most popular Json.NET Converters package from the Assets Store) to create an UPM package for delivering custom converters for the most common Unity types. A package that I guess neither Unity nor James will consider producing.

  • Unity have gotten in contact and forked my repo and are now actually publishing some versions of my repo as the Newtonsoft.Json UPM package, officially built and verified by Unity, to their main UPM registry. Their package is already available from Unity v2020 but they plan to also make it available for lower version. Once their package is fully up and running I will consider just forwarding my package over to the Unity official package, but my Converters repo will continue living on.

There are some greater amount of work being put into making Newtonsoft.Json available to Unity (and particularly IL2CPP). I can only guess James' intention here being that he want to focus on supporting the .NET platform and let community around it make it available to other variants, as he seems to be putting less time into this project at the moment. Just merging this also makes him responsible for maintaining it and all of the sudden have to answer all Unity-specific questions. These are just speculations of course. Maybe @JamesNK can enlighten us with his intentions on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Unity3d Engine support
9 participants